
<!doctype html>
<html>
<head>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<?php echo mate($seo);?>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Home/TemplateDefault/css/default.css">
<link rel="stylesheet" type="text/css" href="/Public/css/animate.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/bootstrap/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Home/TemplateDefault/css/picbox.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/star-rating.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/loader.css">
<script src="__PUBLIC__/Admin/bootstrap/js/jquery.min.js"></script>



<script src="/Public/Js/animate.js"></script>


<script type="text/javascript" src="__PUBLIC__/Js/ElementFlex/jquery.flex.js"></script>


<script src="__PUBLIC__/Admin/bootstrap/js/bootstrap.min.js"></script>






<script src="__PUBLIC__/Home/TemplateDefault/js/jquery.cookie.js"></script>




</head>
<body>
<div class="container containerfirst" style="padding:20px;"> 




<style>







ul.countdown<?php echo $v['id'];?> {
	list-style: none;
	padding: 0;
	display: block;
	text-align: center;
    background: #FF7470;
}
ul.countdown<?php echo $v['id'];?> li {
	display: inline-block;
    color:#fff;
}
ul.countdown<?php echo $v['id'];?> li span {
	font-size: 20px;
    font-weight: 900;
    line-height: 22px;
    padding: 4px; 
   /*  border: 1px solid #ccc;border-radius: 4px; 
    box-shadow: 0 0 5px #ccc inset;*/
    margin: 0 2px; 
}
ul.countdown<?php echo $v['id'];?> li.seperator {
	font-size: 12px;
	line-height: 24px;
    color:#fff;
}
ul.countdown<?php echo $v['id'];?> li p {
	color: #a7abb1;
	font-size: 12px;
} 
 


  .myBox<?php echo $v['id'];?> .cartButton .col{padding:0;}
  .myBox<?php echo $v['id'];?> .cartButton .col .btn{border:none; height:50px; line-height:50px; padding:0 12px; font-weight:bold; font-size:1.3em;}
  .myBox<?php echo $v['id'];?> .remark{color:#f00; padding:0 8px; font-size:12px;}
  
  .myBox<?php echo $v['id'];?> .price{padding:0 8px;}
  .myBox<?php echo $v['id'];?> .dgscp-c{padding:0 8px;}
  .myBox<?php echo $v['id'];?> .dgscp-c .bt strong{color:#7B7B7B;}
  .myBox<?php echo $v['id'];?> .share{ vertical-align:middle; text-align:center;}
  .myBox<?php echo $v['id'];?> .share .fa{width:30px; height:30px; line-height:30px; text-align:center; color:#FF5252; font-size:18px; border-radius:20px; border:1px solid #ccc;}
  
  
  .myBox<?php echo $v['id'];?> .supplier{padding:0 8px; display:none;}
  
.myBox<?php echo $v['id'];?> .cartButton .col .fa{color:#F10B47;}
  .myBox<?php echo $v['id'];?> img{max-width:100%;}
  .myBox<?php echo $v['id'];?> .badge{background:none; color:#333;}
  .myBox<?php echo $v['id'];?> .badge i{font-size:0.7em;}
  .myBox<?php echo $v['id'];?> .panel-body{padding:<?php echo $v['padding'];?>}
  .myBox<?php echo $v['id'];?> .panel{border-radius:0; margin-bottom:0; border:none; box-shadow:none;}
  .myBox<?php echo $v['id'];?> .panel-heading{border-radius:0;}
  .myBox<?php echo $v['id'];?> .panel-heading .badge{float:right;}
  .myBox<?php echo $v['id'];?> .list-group{margin-bottom:0;}
  .myBox<?php echo $v['id'];?> .panel-body{<?php getModulesBorder($v);?>} 
  .myBox<?php echo $v['id'];?>{<?php echo getModulesStyle($v);?>}
  <?php echo str_replace('{id}',$v['id'],$v['style']);?> 


  

</style>


<div class="viewBox myBox<?php echo $v['id'];?>" <?php if($_SESSION[C('USER_AUTH_KEY')]){?> sortID="<?php echo $v['sort'];?>" modulesID="<?php echo $v['id'];?>" title="<?php echo $v['title'];?>" deleteUrl="<?php echo U('/Admin/Modules/delete',array('id'=>$v['id']));?>" settingUrl="<?php echo U('/Admin/Modules/edit',array('id'=>$v['id']));?>" isEdit="0"<?php }?>>
  <?php if(!empty($v['dataname'])){
                $v['content'] = $v['dataname'];
                
        }
         ?>
         <div class="panel panel-primary">
    <?php include(TMPL_PATH.'Home/TemplateDefault/Public-Moduletitle'.C('TMPL_TEMPLATE_SUFFIX')); ?>
<div class="panel-body">




<?php if($skuList){?> 

<style type="text/css">
.bh-sku-selected {color: red; background:#fff; border:1px solid #FF0033;}
input{border:1px solid #ccc; border-radius:0px; background:#fff; outline:none; border-radius:2px;}
input[disabled="disabled"]{border:1px solid #ccc; background:#eee; color:#fff;}
</style>

<link type="text/css" rel="stylesheet" href="/sku/css/shCore.css" />
<link type="text/css" rel="stylesheet" href="/sku/css/shCoreDefault.css"/>
<script type="text/javascript" src="/sku/js/json2.js"></script>
<script type="text/javascript" src="/sku/js/shCore.js"></script>
<script type="text/javascript" src="/sku/js/shBrushJScript.js"></script>






<script type="text/javascript">
var startTime = new Date().getTime();
var data;
//销售属性集
$.get('<?php echo U('Ajax/getSKU');?>', {id:<?php echo $id;?>,time:startTime}, function(r){
	data = r;
	setSKU();
},'json');
//后台读取结果集

//保存最后的组合结果信息
var SKUResult = {};
//获得对象的key
function getObjKeys(obj) {
    if (obj !== Object(obj)) throw new TypeError('Invalid object');
    var keys = [];
    for (var key in obj)
        if (Object.prototype.hasOwnProperty.call(obj, key))
            keys[keys.length] = key;
    return keys;
}

//把组合的key放入结果集SKUResult
function add2SKUResult(combArrItem, sku) {
	var key = combArrItem.join(";");
    if(SKUResult[key]) {
        SKUResult[key].count += sku.count;
        SKUResult[key].prices.push(sku.price);
    } else {
        SKUResult[key] = {
            count : sku.count,
            prices : [sku.price]
        };
    }
}

//初始化得到结果集
function initSKU() {
    var i, j, skuKeys = getObjKeys(data);
    for(i = 0; i < skuKeys.length; i++) {
        var skuKey = skuKeys[i];//一条SKU信息key
        var sku = data[skuKey];	//一条SKU信息value
        var skuKeyAttrs = skuKey.split(";"); //SKU信息key属性值数组
		skuKeyAttrs.sort(function(value1, value2) {
			return parseInt(value1) - parseInt(value2);
		});

        //对每个SKU信息key属性值进行拆分组合
		var combArr = combInArray(skuKeyAttrs);
		for(j = 0; j < combArr.length; j++) {
			add2SKUResult(combArr[j], sku);
		}

        //结果集接放入SKUResult
        SKUResult[skuKeyAttrs.join(";")] = {
            count:sku.count,
            prices:[sku.price]
        }
    }
}

/**
 * 从数组中生成指定长度的组合
 * 方法: 先生成[0,1...]形式的数组, 然后根据0,1从原数组取元素，得到组合数组
 */
function combInArray(aData) {
	if(!aData || !aData.length) {
		return [];
	}

	var len = aData.length;
	var aResult = [];

	for(var n = 1; n < len; n++) {
		var aaFlags = getCombFlags(len, n);
		while(aaFlags.length) {
			var aFlag = aaFlags.shift();
			var aComb = [];
			for(var i = 0; i < len; i++) {
				aFlag[i] && aComb.push(aData[i]);
			}
			aResult.push(aComb);
		}
	}
	
	return aResult;
}


/**
 * 得到从 m 元素中取 n 元素的所有组合
 * 结果为[0,1...]形式的数组, 1表示选中，0表示不选
 */
function getCombFlags(m, n) {
	if(!n || n < 1) {
		return [];
	}

	var aResult = [];
	var aFlag = [];
	var bNext = true;
	var i, j, iCnt1;

	for (i = 0; i < m; i++) {
		aFlag[i] = i < n ? 1 : 0;
	}

	aResult.push(aFlag.concat());

	while (bNext) {
		iCnt1 = 0;
		for (i = 0; i < m - 1; i++) {
			if (aFlag[i] == 1 && aFlag[i+1] == 0) {
				for(j = 0; j < i; j++) {
					aFlag[j] = j < iCnt1 ? 1 : 0;
				}
				aFlag[i] = 0;
				aFlag[i+1] = 1;
				var aTmp = aFlag.concat();
				aResult.push(aTmp);
				if(aTmp.slice(-n).join("").indexOf('0') == -1) {
					bNext = false;
				}
				break;
			}
			aFlag[i] == 1 && iCnt1++;
		}
	}
	return aResult;
} 



//初始化用户选择事件
function setSKU() {
	initSKU();
	
	var endTime = new Date().getTime();
	$('#init_time').text('init sku time: ' + (endTime - startTime) + " ms");
	$('.sku').each(function() {
		var self = $(this);
		var attr_id = self.attr('attr_id');
		if(!SKUResult[attr_id]) {
			self.attr('disabled', 'disabled');
		}
	}).click(function() {
		var self = $(this);

		//选中自己，兄弟节点取消选中
		self.toggleClass('bh-sku-selected').siblings().removeClass('bh-sku-selected');
		
		//已经选择的节点
		var selectedObjs = $('.bh-sku-selected');

		if(selectedObjs.length) {
			//获得组合key价格
			var selectedIds = [];
			selectedObjs.each(function() {
				selectedIds.push($(this).attr('attr_id'));
			});
			selectedIds.sort(function(value1, value2) {
				return parseInt(value1) - parseInt(value2);
			});
			var len = selectedIds.length;
			var prices = SKUResult[selectedIds.join(';')].prices;
			var maxPrice = Math.max.apply(Math, prices);
			var minPrice = Math.min.apply(Math, prices);
			$('#price').text(maxPrice > minPrice ? minPrice + "-" + maxPrice : maxPrice.toFixed(2));
			
			$('#price_').text(maxPrice > minPrice ? '--' : (maxPrice.toFixed(2)/<?php echo $discount;?>).toFixed(0));
			
			
			$('#stock').html(SKUResult[selectedIds.join(';')].count);

			//用已选中的节点验证待测试节点 underTestObjs
			$(".sku").not(selectedObjs).not(self).each(function() {
				var siblingsSelectedObj = $(this).siblings('.bh-sku-selected');
				var testAttrIds = [];//从选中节点中去掉选中的兄弟节点

				if(siblingsSelectedObj.length) {
					var siblingsSelectedObjId = siblingsSelectedObj.attr('attr_id');
					for(var i = 0; i < len; i++) {
						(selectedIds[i] != siblingsSelectedObjId) && testAttrIds.push(selectedIds[i]);
					}
				} else {
					testAttrIds = selectedIds.concat();
				}
				testAttrIds = testAttrIds.concat($(this).attr('attr_id'));
				testAttrIds.sort(function(value1, value2) {
					return parseInt(value1) - parseInt(value2);
				});
				if(!SKUResult[testAttrIds.join(';')]) {
					$(this).attr('disabled', 'disabled').removeClass('bh-sku-selected');
				} else {
					$(this).removeAttr('disabled');
				}
			});
		} else {
			//设置默认价格
			$('#price').text('<?php echo $price;?>');
			$('#stock').html('<?php echo $stocks;?>');
			//设置属性状态
			$('.sku').each(function() {
				SKUResult[$(this).attr('attr_id')] ? $(this).removeAttr('disabled') : $(this).attr('disabled', 'disabled').removeClass('bh-sku-selected');
			})
		}
	});
}
</script>







<?php } ?>


<div class="panel panel-default">

        <div class="panel panel-default">
          <h1 style="margin-top:0; padding-top:0.5em; padding-left:0.5em; padding-right:0.5em; font-size:18px;"><?php echo $title;?></h1>
          
          <gt name="supplier_id" value="0">
          <p class="supplier"><?php echo getSupplier($supplier_id); ?></p>
          </gt>
          
          <notempty name="remark">
          <p class="remark"><?php echo $remark; ?></p>
          </notempty>
           
          
          <div style="position:relative;"><p class="price"><strong style="color: #f00;" >¥<span id="price" style="font-size:24px; font-family:Arial;"><?php echo $price; ?></span></strong>
          
          <!-- 折扣 -->
          
         
          <!-- 折扣结束 -->
         </p>
         
         
         
          
          
          
      
          
          
          
          </div>
          
         <div class="panel-footer" style="padding:0; background:#fff;" >
         <?php foreach($skuList as $key => $voattr){?>
         
         <p style="margin-bottom:4px;"></p>
         
          <div class="dgscp-c" style="display:table">
          
          
          <h5 class="bt attrtitle" style="display:table-cell; min-width:40px;"><strong><?php echo $voattr['title'];?></strong></h5>
          
          
          
          <div style="display:table-cell;"><?php foreach($voattr['list'] as $key => $vattr){?>
          <input class="sku" type="button"  attr_id="<?php echo $vattr['id'];?>" value="<?php echo $vattr['val'];?>" style="margin:5px;"/>
          <?php }?></div>
          
          
          
          </div>
          
          <?php }?>
          
          
          
          
          
          <?php if($skuList){?>
          
          <p style="margin-bottom:10px; border-top:1px solid #CDCDCD; margin-top:5px;"></p>
<?php }else{?>
<div style="height:10px;"></div>
<?php }?>





<?php if(count($systemagentprice) == 1 && $systemagentprice[0]['num'] == 0){?>



<form id="CreateSite<?php echo $v['id'];?>" action="<?php echo U('createreneworder');?>" method="post">
<input type="hidden" name="siteid" value="<?php echo $siteid;?>">
<input id="total_" class="form-control cartNum" style="text-align:center; display:none; width:100px; box-shadow:none;" type="text" name="num" value="0">
</form>
<!-- 如果可以按月开通 -->



<div class="row cartButton" style="position:fixed; bottom:12px; width:0; left:0; width:100%; background:#fff; z-index:200; padding:5px 0;">

    
    <button type="submit" class="btn btn-danger addCartButtonQuick" style="border-radius:4; font-size:18px; margin:0 auto; width:90%; display:block;" >确认支付</button>
    
</div>



<?php }else{?>


<div class="dgscp-c" style="display:table; width:100%;"><h5 class="bt" style="display:table-cell; vertical-align:middle; max-width:15px;"><strong style="color:#000;">续费</strong></h5>
<form id="CreateSite<?php echo $v['id'];?>" action="<?php echo U('createreneworder');?>" target="_blank" method="post">

<input type="hidden" name="goods_id" value="<?php echo $goods_id;?>">
<div style="display:table-cell; max-width:40px;">
<div class="input-group input-group-sm">
      <span class="input-group-btn">
        <button style="margin-right:-2px;" class="btn btn-default sub_" type="button">-</button>
      </span>
      <input id="total_" class="form-control cartNum" style="text-align:center; display:inline; width:100px; box-shadow:none;" type="text" name="num" value="1">
    
       
      
      <span class="input-group-btn">
        <button class="btn btn-default add_" type="button">+</button>
      </span>
      
      
      
    </div>

</div>



<div class="row cartButton" style="position:fixed; bottom:12px; width:0; left:0; width:100%; background:#fff; z-index:200; padding:5px 0;">

    
    <button type="submit" class="btn btn-danger addCartButtonQuick" style="border-radius:4; font-size:18px; margin:0 auto; width:90%; display:block;" >确认支付</button>
    
</div>

</form>
<h5 class="bt" style="display:table-cell; vertical-align:middle; max-width:15px;"><strong style="color:#000;"> 个月</strong></h5>

</div>

<!-- 如果可以按月开通end -->
<p style="margin-bottom:5px; border-top:1px solid #CDCDCD; margin-top:10px;"></p>
<?php }?>



          </div>
        </div>
      </div>    
<div style="clear:both;"></div>




<!-- 下方按钮 -->






<!-- 下方按钮结束 -->
       
 <div style="clear:both"></div>      
       
       
       
       
       
<script>

$('.add_').click(function(e) {
	var val = $(this).parent().prev('input').eq(0).val()*1;
	$(this).parent().prev('input').eq(0).val(val + 1);
	updateCartNum();
	
});
$('.sub_').click(function(e) {
    var val = $(this).parent().next('input').eq(0).val()*1;
	if(val > 1){
		$(this).parent().next('input').eq(0).val(val - 1);
	}
	updateCartNum();
});
$('#total_').keypress(function(e) {
    updateCartNum();
});

	function addCart(){
		
	}
	
	function addCart_quick(){
		$('#CreateSite<?php echo $v['id'];?>').submit();
	}
	
	
	
	
	function updateCartNum(){
		$('#price').html('计算中……');
		setTimeout(function(){
			$.ajax({
			url:"<?php echo U('getSitePriceByNumrenew');?>",
			data:"siteid=<?php echo $_GET['id'];?>&num="+$('#total_').val(),
			type:'POST',
			dataType:"html",
			success: function(data){
				$('#price').html(data);
			}
		});
		}, 50);
		
	}
	 
	$(document).ready(function(e) {
		updateCartNum();
    });
	
	
</script>



</div>
</div></div>



















</div>






</body>
</html>

